#pragma  once 
#include<iostream>
#include<unistd.h>
#include<fcntl.h>
#include"com.hpp"
//设置一个sock成为非阻塞
void SetNonBlock(int sock)
{
  int f1 = fcntl(sock,F_GETFL);
  if(f1<0)
  {
    std::cerr<<"fcntl failed"<<std::endl;
  }

  fcntl(sock,F_SETFL,f1|O_NONBLOCK);

}

void  SplitSegment(string& inbuffer,vector<string>* tokens,string sep)
{
  while(true)
  {
    cout<<"inbuffer: "<<inbuffer<<endl;
    auto pos = inbuffer.find(sep); 
    if(pos==string::npos)
    {
      break;
    }
    string sub= inbuffer.substr(0,pos);//[) 
    tokens->push_back(sub);
    inbuffer.erase(0,pos+sep.size());
  }
}

bool Deserialize(const string &seg,string* out1,string *out2)
{
  auto pos = seg.find("+");
  if(pos==string::npos)
  {
    return false;
  }

  *out1=(seg).substr(0,pos);
  *out2=(seg).substr(pos+1);
  return true;
}


